package com.wdl.sm.webui.yang.node;

import java.util.ArrayList;
import java.util.List;

import com.nokia.taiji.yang.schema.SNI;
import com.nokia.taiji.yang.schema.SchemaNode;
import com.nokia.taiji.yang.schema.YANG_List;
import com.nokia.taiji.yang.schema.YANG_List.Unique;
import com.wdl.sm.webui.yang.YANGExt;

public class ListNode extends NormalizedNode {
    String minElements;
    String maxElements;

    List<String> uniques = new ArrayList<String>();

    String[] keys;
    String fields;

    List<Object> elements = new ArrayList<Object>();

    public ListNode(YANG_List node) {
        super(node);

        keys = node.getKeys();
        if (keys == null) {
            keys = new String[0];
        }

        minElements = String.valueOf(node.getMinElem());
        maxElements = String.valueOf(node.getMaxElem());
        List<Unique> tmps = node.getUniques();
        if (tmps != null && !tmps.isEmpty()) {
            for (Unique unique : tmps) {
                if (unique.unique != null) {
                    for (SNI sni : unique.unique) {
                        String sniString = sni.toString();
                        if (!uniques.contains(sniString)) {
                            uniques.add(sniString);
                        }
                    }
                }
            }
        }

        List<SchemaNode> children = node.getChildren();
        if (children == null || children.isEmpty()) {
            return;
        }

        for (SchemaNode child : children) {
            Object element = YANGExt.buildWebuiYangNode(child);
            if (element != null) {
                elements.add(element);
            }
        }
    }

    public String getMinElements() {
        return minElements;
    }

    public void setMinElements(String minElements) {
        this.minElements = minElements;
    }

    public String getMaxElements() {
        return maxElements;
    }

    public void setMaxElements(String maxElements) {
        this.maxElements = maxElements;
    }

    public String[] getKeys() {
        return keys;
    }

    public void setKeys(String[] keys) {
        this.keys = keys;
    }

    public List<Object> getElements() {
        return elements;
    }

    public List<String> getUniques() {
        return uniques;
    }

    public void setUniques(List<String> uniques) {
        this.uniques = uniques;
    }
}
